package com.cskaoyan.controller;


import com.cskaoyan.bean.baseresultVO.BaseData;
import com.cskaoyan.bean.baseresultVO.BaseRespVo;
import com.cskaoyan.bean.domain.Category;
import com.cskaoyan.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * <p>
 * 类目表 前端控制器
 * </p>
 *
 * @author looper
 * @since 2021-11-29
 */
@RestController
@RequestMapping("admin/category")
public class CategoryController {
    @Autowired
    CategoryService service;

    @GetMapping("l1")
//    @GetMapping("/{1L}")
    public BaseRespVo getL1() {

        Integer i = 1;
        //返回一级目录
        BaseData baseData = service.getCategory(i);
        return BaseRespVo.ok(baseData);
    }

    @GetMapping("list")
    public BaseRespVo getList() {

        BaseData baseData = service.getList();
        return BaseRespVo.ok(baseData);
    }

    @PostMapping("update")
    public BaseRespVo getUpdate(@RequestBody Category category) {
        //更新时间
        Date date = new Date();
        category.setUpdateTime(date);
        service.getUpate(category);
        return BaseRespVo.ok(null);
    }

    @PostMapping("create")
    public BaseRespVo getCreate(@RequestBody Category category) {
        //addtime
        Date date = new Date();
        category.setAddTime(date);
        Category categoryReturn = service.getInsert(category);
        return BaseRespVo.ok(categoryReturn);
    }


    @PostMapping("delete")
    public BaseRespVo getDelete(@RequestBody Category category) {
        //updatetime+逻辑删除
        Integer id = category.getId();
        Integer code = service.getDeleteById(id);

       return  BaseRespVo.ok(null);
    }

}

